package com.example.test02

import android.annotation.SuppressLint
import android.os.Bundle
import android.widget.Button
import android.widget.LinearLayout
import android.widget.Spinner
import android.widget.TextView
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat

class MainActivity : AppCompatActivity() {
    private val expert = ProgramExpert()
    @SuppressLint("SetTextI18n")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_main)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }

        val scrollViewLayout = findViewById<LinearLayout>(R.id.scroll_layout)
        val addTextViewBtn = findViewById<Button>(R.id.add_textview)
        var count = 1
        addTextViewBtn.setOnClickListener {
            val textView = TextView(this).apply {
                text = "This is a new TextView: $count"
                count ++
            }
            scrollViewLayout.addView(textView)
        }

        val sure = findViewById<Button>(R.id.sure)
        sure.setOnClickListener {
            val selectedFeature = findViewById<Spinner>(R.id.spinner).selectedItem.toString()
            findViewById<TextView>(R.id.textView).text = expert.getLanguage(selectedFeature)
        }
    }
}